﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace Medianamik.Core.DAL.SQL
{
    public interface ITable
    {
        string Name { get; }
        string Alias { get; }
        string Schema { get; }
        Column this[string pColumnName]
        { 
            get;
        }

        bool Contains(string pColumnName);
    }

    public class Table : ITable
    {
        public string Name { get; private set; }
        public string Alias { get; private set; }
        public string Schema { get; private set;}

        private Dictionary<string,Column>  _columns;
        public IEnumerable<Column> Columns
        {
            get
            {
                return _columns.Values;
            }
        }

        public Table(string pTableName, string pTableAlias)
        {
            Name = pTableName;
            Alias = pTableAlias;
            Schema = "dbo";
            _columns = new Dictionary<string, Column>();
        }

        public Column AddColumn(string pColumnName)
        {
            var col = new Column(this, pColumnName);
            _columns.Add( pColumnName.ToLowerInvariant(),col );
            return col;
        }

        public Column this[string pColumnName]
        {
           get
           {
               return _columns[pColumnName.ToLowerInvariant()]; 
           }
        }

        public bool Contains(string pColumnName)
        {
            return _columns.ContainsKey(pColumnName.ToLowerInvariant());
        }

    }
}
